 
 /**
  *picc项目页面
  *
  */
 LrtWidget=OpenLayers.Class(BaseWidget,{
 	//构造函数
 	initialize : function() {
	},
	//返回组装好的地图切换控件dom对象
	getElement : function(){
		if(!this.element){
			if(this.config){
				//加载依赖的分页组件
				this.requireWidgetJs(this.config.jqPaginationJs);
				this.requireWidgetCSS(this.config.jqPaginationCss);
				this.element = this.createElement(this.map);
			}
		}
		return this.element;
	},
	createElement : function(){
		var $this=this;
		var LrtBox=$('<div id="LrtWidget">'+
				'<div id="TitleBar">'+
					'<input id="txtSearch" type="text" />'+
					'<div id="btnSearch">搜索</div>'+
					'<div>'+
						'<div id="TabQuery4S" class="TabCommon SelectTab" name="yiyuan">医院</div>'+
						
						'<div id="TabQueryServry" class="TabCommon NormalTab" name="chelian">车辆</div>'+
						'<div id="TabQueryPoi" class="TabCommon NormalTab" name="zhognduan">人员</div>'+
						/*
						'<div  id="TabQueryDzbm" class="TabCommon NormalTab">地址编码</div>'+
						*/
					'</div>'+
					'<div id="barHSBtn"></div>'+
				'</div>'+
				'<div id="barHSBtn2"></div>'+
				'<div id="layer"><div class="layer-open-close"></div></div>'+
				'<div class="track-but" style="padding: 0 0px;"></div>'+
				'<div class="chelian-status"></div>'+
				'<div class="chelian-total"></div>'+
				'<div class="track-date-win" title="查勘员轨迹查询"></div>'+
			'</div>'
		);
		LrtBox.addClass('widget-class');
		/*初始化窗体*/
		LrtBox.find(".track-date-win").dialog({
				width : 275,
				minWidth: 260,
				maxWidth : 280,
				minHeight: 220,
				maxHeight :230,
				autoOpen : false
		});
		
		LrtBox.css({
			'font-size' :'12px',
			'top' :'0px',
			'left' :'0px'
		}).find("#TitleBar").css({
			'background-image' : 'url(images/custom/lrt_banner.png)',
			'height':'75px',
			'width' :'580px',
			'background-repeat' : 'no-repeat'
		}).end().find('#txtSearch').css({
			'width' :'236px',
			'height' :'20px',
			'margin-left' :'179px',
			'margin-top' :'9px'
		}).keydown(function(e){
			if(e.keyCode==13){
				PiccBox.find("#btnSearch").trigger('click');
			}
		}).end().find('#btnSearch').css({
			'color' :'#668d95',
			'font-family' :'微软雅黑',
			'height' :'28px',
			'font-size':'14px',
			'top' :'8px',
			'position' :'absolute',
			'left' :'420px',
			'width' :'46px',
			'padding-left':'12px',
			'padding-top':'2px',
			'cursor' :'pointer'
		}).click(function(){
			if($this.POILayer==null){
				$this.POILayer = new OpenLayers.Layer.Markers("markers");
				$this.POILayer.setZIndex(200);
        		$this.map.addLayer($this.POILayer); 
			}
			LrtBox.find(".TabCommon").each(function(a,b){
				if($(this).hasClass("SelectTab")){
					var name=$(this).attr("name");
					if(name=="yiyuan"){
						//poi搜索
						var config = {
							localProxyUrl : $this.config.localProxyUrl,
							ServerUrl : $this.config.poiServerUrl
						}
						var key=$("#txtSearch").val();
						$this.poiRequestData={
							name : key,
							currentPage :1,
							pageSize : 10
						};
						$this.POISearch(config,$this.poiRequestData);
					}else if(name=="chelian"){
					
					}else if(name=="zhognduan"){
					
					}
				}
				
			});
			
			
			
		}).end().find('.TabCommon').css({
			'position' :'absolute',
			'text-align' :'center',
			'line-height' :'27px',
			'width' :'82px',
			'height' :'27px',
			'top' :'44px',
			'cursor' :'pointer'
		}).click(function(){
			$(this).css({
				'background-image' :'url(images/custom/tab_slect.png)'
			}).siblings().css({
				'background-image' :'url(images/custom/tab_normal.png)'
			}).end().siblings().removeClass("SelectTab").end().addClass("SelectTab");
		}).end().find('.SelectTab').css({
			'background-image' :'url(images/custom/tab_slect.png)'
		}).end().find('.NormalTab').css({
			'background-image' :'url(images/custom/tab_normal.png)'
		}).end().find('#TabQuery4S').css({
			'left' :'180px'
		}).end().find('#TabQueryServry').css({
			'left' :'270px'
		}).end().find('#TabQueryPoi').css({
			'left' :'360px'
		}).end().find('#TabQueryDzbm').css({
			'left' :'493px'
		}).end().find('#barHSBtn').click(function(){
			PiccBox.find('#TitleBar').hide();
			PiccBox.find("#barHSBtn2").show();
		}).css({
			'position':'absolute',
			'width' :'24px',
			'background' :'url(images/custom/left_up.png)',
			'height' :'28px',
			'top' :'9px',
			'cursor' :'pointer',
			'left' :'480px'
		}).mouseover(function(){
			$(this).css({
				'background' :'url(images/custom/left_over.png)'
			})
		}).mouseout(function(){
			$(this).css({
				'background' :'url(images/custom/left_up.png)'
			})
		}).end().find('#barHSBtn2').css({
			'position':'absolute',
			'display' :'none',
			'background' :'url(images/custom/right_up.png)',
			'width':'24px',
			'height' :'28px',
			'top' :'0px',
			'left' :'0px',
			'cursor' :'pointer'
		}).click(function(){
			$(this).hide();
			PiccBox.find('#TitleBar').show();
		}).mouseover(function(){
			$(this).css({
				'background' :'url(images/custom/right_over.png)'
			})
		}).mouseout(function(){
			$(this).css({
				'background' :'url(images/custom/right_up.png)'
			})
		}).end().find("#layer").css({
			'position':'absolute',
			 'left' :'540px',
			 'top'  : '15px'
		}).end().find("#layer .layer-open-close").css({
			'background' :'url(images/custom/lrt_xianshiyiyuan.png)',
			'width' :'77px',
			'height' :'28px',
			'cursor' :'pointer'
		}).toggle(function(){
			/*设置背景图片切换*/
			$(this).css({
				'background' :'url(images/custom/lrt_yincangyiyuan.png)'
			});
			if($this.LayerWms==null){
				$this.LayerWms = new OpenLayers.Layer.WMS(
                    "Geoserver layers - Tiled",
                    "proxy.jsp?http://localhost:8787/geoserver/zjlwm/wms?",
                    //"http://localhost:8181/geoserver/cite/wms",
                    {
                        //LAYERS: 'zjlwm:yiyuan',
                        LAYERS: 'cite:yiyuan',
                        STYLES: '',
						transparent:true, //背景透明设置
                        format: 'image/png',
                        tiled: true,
                        tilesOrigin : $this.map.maxExtent.left + ',' + $this.map.maxExtent.bottom
                    },
                    {
                        buffer: 0,
                        displayOutsideMaxExtent: true,
                        isBaseLayer: false,
                        yx : {'EPSG:900913' : true}
                    } 
                );
			}else{
				$this.LayerWms.setVisibility(true);
			}
             $this.map.addLayers([$this.LayerWms]);
             $this.map.events.register('moveend',$this.map,function(e){
             	var box=$this.map.getExtent().transform($this.map.getProjectionObject(),$this.map.displayProjection);
             	var config = {
					localProxyUrl : $this.config.localProxyUrl,
					ServerUrl : $this.config.RectQueryUrl
				}
				var rectpointStr=box.left+" "+box.bottom+","+box.right+" "+box.top;
				var requestData={
					 layerId : $this.config.layerName,
					 rectpointStr :rectpointStr
				}
				/*
             	Interface.jsonRequest3(config,requestData, function(list, config) {
             		for(var i=0;i<list.size;i++){
             		
             		}
             	});
             	*/
             });
             
             $this.LayerWms.events.register('click',$this.LayerWms,function(e){
             	var startPiex=new OpenLayers.Pixel(0,0);
             	var lonlatstart=this.map.getLonLatFromPixel(startPiex).transform(this.map.getProjectionObject(),this.map.displayProjection);
                var endPiex=new OpenLayers.Pixel(0,5);
                var lonlatend=this.map.getLonLatFromPixel(endPiex).transform(this.map.getProjectionObject(),this.map.displayProjection);
                var y=lonlatstart.lat-lonlatend.lat;
                
             	 var piex=new OpenLayers.Pixel(e.clientX,e.clientY);
             	 var center=this.map.getLonLatFromPixel(piex).transform(this.map.getProjectionObject(),this.map.displayProjection);
             	
             	 var config = {
					localProxyUrl : $this.config.localProxyUrl,
					ServerUrl : $this.config.CircleUrl
				}
				var requestData={
					 layerId : $this.config.layerName,
					 center : center.lon+" "+center.lat,
					 radius : y
				}
				
				Interface.jsonRequest3(config,requestData, function(list, config) {
					if($this.popup!=null){
	                		$this.map.removePopup($this.popup);
				    		//$this.popup.destroy();
				    		$this.popup = null;
				     }
             		if(list.length>0){
             			var data=list[0];
             			var address=data.addr_line;
						var name=data.aname;
						var sm=data.name;
						var x=data.x;
						var y=data.y;
						var lonlat=new OpenLayers.LonLat(x,y).transform($this.map.displayProjection,$this.map.getProjectionObject());
				        
				        var content="<div class='popup-container' style='width:270px;height:140px;font-size:12px;#666;'>"+
			                				"<div class='popup-header' style='font-size:14px;color:blue;'>"+name+"</div>"+
			                				"<div class='popup-body'>"+
			                					'<table width=100%;>'+
			                						//'<tr><td style="width:40px;">地址：</td><td>'+address+'</td></tr>'+
			                						'<tr>'+
			                							'<td>'+
			                								'<p>地址：'+address+'</p>'+
			                								'<p>说明：'+sm+'</p>'+
			                							'</td>'+
			                						'</tr>'+
			                						'<tr><td></td><td></td></tr>'+
			                						'<tr><td></td><td></td></tr>'+
			                						'<tr><td></td><td></td></tr>'+
			                					'</table>'+
			                				"</div>"+
		                				"</div>";
		               	 	$this.popup = new OpenLayers.Popup.FramedCloud(
		               	 	   "chicken",
			                    lonlat,
			                    null,
			                    content,
			                    null,
			                    true,
			                    function(popup){
			                    	if($this.popup!=null){
				                		$this.map.removePopup($this.popup);
							    		//$this.popup.destroy();
							    		$this.popup = null;
				                	}
			                    }
			              	 );
			               	$this.map.addPopup($this.popup);
             		}
             });
             });
             /*
             $this.map.events.register('click',$this.map,function(e){
             	 var dradius=5*1/this.baseLayer.resolutions[this.getZoom()]*1000;
             	 var lonlat=this.getLonLatFromPixel(e.xy).transform($this.map.getProjectionObject(),$this.map.displayProjection);
             	 var piex=new OpenLayers.Pixel(parseFloat(e.xy.x+dradius),e.xy.y);
             	 var lonlat2=this.getLonLatFromPixel(piex).transform($this.map.getProjectionObject(),$this.map.displayProjection);
             	 var x=lonlat2.lon-lonlat.lon;
             	 var config = {
					localProxyUrl : $this.config.localProxyUrl,
					ServerUrl : $this.config.CircleUrl
				}
				var requestData={
					 layerId : $this.config.layerName,
					 center : lonlat.lon+" "+lonlat.lat,
					 radius : x
				}
				
				Interface.jsonRequest3(config,requestData, function(list, config) {
					if($this.popup!=null){
	                		$this.map.removePopup($this.popup);
				    		//$this.popup.destroy();
				    		$this.popup = null;
				     }
             		if(list.length>0){
             			var data=list[0];
             			var address=data.addr_line;
						var name=data.aname;
						var x=data.x;
						var y=data.y;
						var lonlat=new OpenLayers.LonLat(x,y).transform($this.map.displayProjection,$this.map.getProjectionObject());
				        
				        var content="<div class='popup-container' style='width:270px;height:140px;font-size:12px;#666;'>"+
			                				"<div class='popup-header' style='font-size:14px;color:blue;'>"+name+"</div>"+
			                				"<div class='popup-body'>"+
			                					'<table width=100%;>'+
			                						'<tr><td style="width:40px;">地址：</td><td>'+address+'</td></tr>'+
			                						'<tr><td></td><td></td></tr>'+
			                						'<tr><td></td><td></td></tr>'+
			                						'<tr><td></td><td></td></tr>'+
			                					'</table>'+
			                				"</div>"+
		                				"</div>";
		               	 	$this.popup = new OpenLayers.Popup.FramedCloud(
		               	 	   "chicken",
			                    lonlat,
			                    null,
			                    content,
			                    null,
			                    true,
			                    function(popup){
			                    	if($this.popup!=null){
				                		$this.map.removePopup($this.popup);
							    		//$this.popup.destroy();
							    		$this.popup = null;
				                	}
			                    }
			              	 );
			               	$this.map.addPopup($this.popup);
             		}
             	});
             	
             });
             */
		},function(){
			$this.LayerWms.setVisibility(false);
			$(this).css({
				'background' :'url(images/custom/lrt_xianshiyiyuan.png)'
			});
		}).end().find(".track-but").css({
			'background' :'url(images/custom/track.png)',
			'width' :'77px',
			'height' :'28px',
			'left' :'620px',
			'top'  : '15px',
			'cursor' :'pointer',
			'position':'absolute'
		}).click(function(){
			var trackwindow=$(".track-date-win");
			trackwindow.empty();
			trackwindow.dialog('open');
			var content=$('<div class="ui-content">'+
				    '<p>查勘员&nbsp;&nbsp; ：<select style="width:160px;"><option>张三</option></select></p>'+
					'<p>开始时间：<input type="text" class="datepicker"/></p>'+
					'<p>结束时间：<input type="text" class="datepicker"/></p>'+
					'<p style="text-align:center;"><input type="button" class="button" value="查询"/></p>'+
			'</div>');
			content.find('.datepicker').css({
				'width' : '160px'
			}).datepicker({
				dateFormat : "yy-mm-dd"
			}).end().find(".button").button();
			trackwindow.append(content);
			trackwindow.dialog({
				autoOpen : true
			});
			
		}).end().find(".chelian-status").css({
			'background' :'url(images/custom/chelian-status.png)',
			'width' :'90px',
			'height' :'28px',
			'left' :'700px',
			'top'  : '15px',
			'cursor' :'pointer',
			'position':'absolute'
		}).end().find(".chelian-total").css({
			'background' :'url(images/custom/chelian-total.png)',
			'width' :'90px',
			'height' :'28px',
			'left' :'790px',
			'top'  : '15px',
			'cursor' :'pointer',
			'position':'absolute'
		});
		return LrtBox;
	},
	LayerWms :null,
	POISearch : function(config,requestData,jqPagination){
		var $this = this;
			Interface.jsonRequest2(config,requestData, function(response, config) {
				if($this.popup!=null){
                		$this.map.removePopup($this.popup);
			    		//$this.popup.destroy();
			    		$this.popup = null;
		        }
				$this.POILayer.clearMarkers();
				var bounds = new OpenLayers.Bounds();
				var list = response.list;
				var count=response.count;
				
				
				
				
				$("#ResultWidget .tabs-1 .rows").empty();
				var table=$('<table cellspacing="0" cellpadding="0"></table>');
				$("#ResultWidget .tabs-1 .rows").append(table);
				//分页
				var remainder=(parseInt(response.count))%10;
					var max_page=0;
					var current_page=1;
					if(remainder==0){
						max_page=parseInt(response.count)/10;
					}else{
						max_page=parseInt(parseInt(response.count)/10)+1;
				}
				if($('#ResultWidget .tabs-1 .pagination').length==0){
						var pageBox=$(
						'<div class="pagination">'+
								  '<br><a href="#" class="first" data-action="first">&laquo;</a>'+
								  '<a href="#" class="previous" data-action="previous">&lsaquo;</a>'+
								  '<input type="text" readonly="readonly" data-max-page="40" />'+
								  '<a href="#" class="next" data-action="next">&rsaquo;</a>'+
								  '<a href="#" class="last" data-action="last">&raquo;</a>'+
							'</div>'
						);
						$("#ResultWidget .tabs-1 .page").append(pageBox);
						
						$('#ResultWidget .tabs-1 .pagination').jqPagination({
						  link_string : '/?page={page_number}',
						  current_page: current_page, //设置当前页 默认为1
						  max_page : max_page, //设置最大页 默认为1
						  page_string : '当前第{current_page}页,共{max_page}页',
						  paged : function(page) {
						      	var requestData=$this.poiRequestData;
						      	requestData.currentPage=page;
						      	var config = {
									localProxyUrl : $this.config.localProxyUrl,
									ServerUrl : $this.config.poiServerUrl
								}
						      	$this.POISearch(config,requestData,'jqPagination');
						     }
						});
						
					}else{
						if(jqPagination==null){
							$("#ResultWidget .tabs-1 .page").empty();
							var pageBox=$(
							'<div class="pagination">'+
									  '<br><a href="#" class="first" data-action="first">&laquo;</a>'+
									  '<a href="#" class="previous" data-action="previous">&lsaquo;</a>'+
									  '<input type="text" readonly="readonly" data-max-page="40" />'+
									  '<a href="#" class="next" data-action="next">&rsaquo;</a>'+
									  '<a href="#" class="last" data-action="last">&raquo;</a>'+
								'</div>'
							);
							$("#ResultWidget .tabs-1 .page").append(pageBox);
							var jqpage=$('#ResultWidget .tabs-1 .pagination').jqPagination({
							  link_string : '/?page={page_number}',
							  current_page: current_page, //设置当前页 默认为1
							  max_page : max_page, //设置最大页 默认为1
							  page_string : '当前第{current_page}页,共{max_page}页',
							  paged : function(page) {
							      	var requestData=$this.poiRequestData;
							      	requestData.currentPage=page;
							      	var config = {
										localProxyUrl : $this.config.localProxyUrl,
										ServerUrl : $this.config.poiServerUrl
									}
							      	$this.POISearch(config,requestData,'jqPagination');
							     }
							});
							//alert("current_page"+current_page);
						}
					}
				var markerClick=null;
				$.each(list, function(index, data) {
						var address=data.addr_line;
						var name=data.aname;
						var sm=data.name;
						var x=data.x;
						var y=data.y;
						var lonlat=new OpenLayers.LonLat(x,y).transform($this.map.displayProjection,$this.map.getProjectionObject());
						bounds.extend(lonlat);
						
						var row=$("<tr>"+
									'<th style="width:31px;"><div clas="icon"></div></th>'+
									'<td style="width:190px;">'
										+"<div><span style='color:#0000CC;'>"+name+"<span></div>"
										+"<div style='color:black;'>地址：<span>"+address+"</span></div>"
									+'</td>'
								+'</tr>');
						table.append(row);
						
						var position='-'+index*24+'px -198px';
						row.find('th div').css({
							'width' :'19px',
							'height' :'25px',
							'background' :'url(images/custom/markers_new.png) no-repeat',
							'background-position' :position
						});
						
						var url = $this.config.icon;
						url='images/custom/markers/red/markers_new_'+(index+1)+'.png';
		                var sz = new OpenLayers.Size(22, 28);  //尺寸大小
		                var calculateOffset = function(size) {
		                    return new OpenLayers.Pixel(-(size.w/2), -size.h);
		                 };
		                var icon = new OpenLayers.Icon(url, sz, null, calculateOffset);
						var marker = new OpenLayers.Marker(lonlat, icon);
		                $this.POILayer.addMarker(marker);
		                marker.events.element.title=name;
		                marker.events.element.style.cursor='pointer';
		                
		                marker.events.register('mouseover', marker, function(evt) {
		               	   
		                	marker.icon.setUrl('images/custom/markers/blue/markers_new_'+(index+1)+'.png');
		                });
		                marker.events.register('mouseout', marker, function(evt) {
		                	marker.icon.setUrl('images/custom/markers/red/markers_new_'+(index+1)+'.png');
		                });
		                
		                row.css({
							'height' :'80px',
							'border-bottom' :'1px solid #D0D0D0',
							'margin-top':'5px',
							'margin-left':'2px',
							'cursor':'pointer'
							
						}).mouseover(function(){
							$(this).css({
								'background-color':'#F0F0F0'
							});
							position='-'+index*24+'px -230px';
							row.find('th div').css({
								'background-position' :position
							});
							marker.icon.setUrl('images/custom/markers/blue/markers_new_'+(index+1)+'.png');
							//marker.events.element.style.zIndex=100000;
							//marker.icon.imageDiv.style.zIndex=100000;
						}).mouseout(function(){
							$(this).css('background-color','white');
							position='-'+index*24+'px -198px';
							row.find('th div').css({
								'background-position' :position
							});
							marker.icon.setUrl('images/custom/markers/red/markers_new_'+(index+1)+'.png');
						}).click(function(){
							$this.map.setCenter(lonlat, 14);  //添加平移缩放工具条
							/*
							if(markerClick!=null){
								markerClick.icon.setUrl('images/custom/markers/red/markers_new_'+(index+1)+'.png');
								marker.icon.setSize(new OpenLayers.Size(30, 41));
							}
							marker.icon.setSize(new OpenLayers.Size(30, 41));
		                	marker.icon.setUrl('images/custom/markers/big/'+(index+1)+'.png');
		                	markerClick=marker;
		                	*/
						});
						
						
						//var markerClick=null;
		                marker.events.register('mousedown', marker, function(evt) {
		                	/*
		                	if(markerClick!=null){
		                		marker.icon.setSize(new OpenLayers.Size(22, 28));
		                		markerClick.icon.setUrl('images/custom/markers/red/markers_new_'+(index+1)+'.png');
		                	}
		                	markerClick=marker;
		                	marker.icon.setSize(new OpenLayers.Size(30, 41));
		                	marker.icon.setUrl('images/custom/markers/big/'+(index+1)+'.png');
		                	*/
		                	
		                	if($this.popup!=null){
		                		$this.map.removePopup($this.popup);
					    		//$this.popup.destroy();
					    		$this.popup = null;
		                	}
		                	var content="<div class='popup-container' style='width:270px;height:140px;font-size:12px;#666;'>"+
			                				"<div class='popup-header' style='font-size:14px;color:blue;'>"+name+"</div>"+
			                				"<div class='popup-body'>"+
			                					'<table width=100%;>'+
			                						//'<tr><td style="width:40px;">地址：</td><td>'+address+'</td></tr>'+
			                						'<tr><td>'+
			                								'<p>地址：'+address+'</p>'+
			                								'<p>说明：'+sm+'</p>'+
			                							'</td></tr>'+
			                						'<tr><td></td><td></td></tr>'+
			                						'<tr><td></td><td></td></tr>'+
			                						'<tr><td></td><td></td></tr>'+
			                					'</table>'+
			                				"</div>"+
		                				"</div>";
		               	 	$this.popup = new OpenLayers.Popup.FramedCloud(
		               	 	   "chicken",
			                    lonlat,
			                    null,
			                    content,
			                    null,
			                    true,
			                    function(popup){
			                    	if($this.popup!=null){
				                		$this.map.removePopup($this.popup);
							    		//$this.popup.destroy();
							    		$this.popup = null;
				                	}
			                    }
			              	 );
			               	$this.map.addPopup($this.popup);
		                	OpenLayers.Event.stop(evt); 
		                });
				});
				
				//进行bounds定位
				$this.map.zoomToExtent(bounds,null);
				//打开数据展示面板
				$("#ResultWidget").show();
				
				
				
			});
	},
	poiRequestData :null,
	POILayer : null,
	popup : null,
	CLASS_NAME:"openGis.LrtWidget"
 });